<template>
  <div class="part-record">
    <base-timeline v-if="items && items.length > 0">
      <base-timeline-item v-for="item in items" :key="item.id">
        <!-- TODO: action为中文，后续跟进 -->
        <template v-if="item.action == '备注'">
          <template v-if="isOpenData && item.executorStaffId">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else> 
            {{item.executorName}}
          </template>
          {{$t('part.components.partRecord.text2', {data1: item.showInOwn == 1?$t('part.components.partRecord.text1'):''})}}
          <template slot="content">
            <p v-if="item.content.updateContent"><biz-comment-html :html="item.content.updateContent"></biz-comment-html></p>
            <base-preview v-if="item.attachments" :files="item.attachments" readonly></base-preview>
          </template>
        </template>

        <template v-else-if="item.action == '编辑'">
          <template v-if="isOpenData && item.executorStaffId">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else>
            {{item.executorName}} 
          </template>
          {{$t('part.components.partRecord.text4')}}

          <template slot="content">
            <p v-if="item.content.updateFieldsStr">{{item.content.updateFieldsStr}}</p>
          </template>
        </template>
        
        <template v-else-if="item.action === 'API新建'">
          <template v-if="isOpenData && item.executorStaffId">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else>
            {{item.executorName}} 
          </template>
          {{$t('part.components.partRecord.text6', {data1: item.content.clientName})}}
        </template>

        <template v-else-if="item.action === 'API编辑'">
          <template>
            <template v-if="isOpenData && item.executorStaffId">
              <open-data type="userName" :openid="item.executorStaffId"></open-data> 
            </template>
            <template v-else>
              {{ item.executorName }} 
            </template>
            {{$t('part.components.partRecord.text8', {data1: item.content.clientName})}}<br>
            {{ Object.keys(item.content).length > 0 ? ( item.content.updateFieldsStr != undefined ? `${$t('common.base.editFields')}：${item.content.updateFieldsStr}` : '' ) : '' }}
          </template>
        </template>

        <template v-else-if="item.action === '设置'">
          <template v-if="isOpenData">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else>
            {{ item.executorName }} 
          </template>
          {{$t('part.components.partRecord.text11', {data1: item.content.repertoryName, data2: item.content.safetyStock})}}
        </template>

        <template v-else-if="item.action === '批量更新'">
          <template v-if="isOpenData && item.executorStaffId">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else>
            {{ item.executorName }} 
          </template>
          {{$t('part.components.partRecord.text13')}}

          <template slot="content">
            <p v-if="item.content.updateFieldsStr">{{item.content.updateFieldsStr}}</p>
          </template>
        </template>

        <template v-else-if="item.action === '取消'">
          <i18n path="part.components.partRecord.text14">
            <template slot="executorName">
              <template v-if="isOpenData && item.executorStaffId">
                <open-data type="userName" :openid="item.executorStaffId"></open-data>
              </template>
              <template v-else>
                {{ item.executorName }}
              </template>
            </template>
            <template slot="repertoryName">
              <template v-if="isOpenData && item.content.repertoryStaffId">
                <open-data type="userName" :openid="item.content.repertoryStaffId"></open-data>
              </template>
              <template v-else>
                {{ item.content.repertoryName }}
              </template>
            </template>
          </i18n>
        </template>

        <template v-else-if="item.action === '发送提醒'">
          <i18n path="part.components.partRecord.text15">
            <template slot="data1">
              <template v-if="isOpenData && item.content && item.content.receiversStaffId">
                <open-data v-for="staffId in item.content.receiversStaffId.split(',')" :key="staffId" type="userName" :openid="staffId"></open-data>
              </template>
              <template v-else>
                {{ item.content.receivers }}
              </template>
            </template>
          </i18n>
        </template>

        <template v-else-if="item.action === '触发器to'">
          {{ item.executorName }}
          &nbsp; 
          {{t('common.connector.record.atMainModule')}}：
          {{ item.content.bizType }}
          &nbsp; 
          {{ t('common.connector.record.triggerMainModuleNoCreateData', {data: item.content.fromBizNo}) }}
        </template>

        <template v-else-if="item.action === '触发器from'">
          {{ $t('common.record.connector.renderTriggerFrom', {
            operator: item.executorName,
            triggerName: item.content.triggerName,
            toBizTypeName: item.content.toBizTypeName,
          })}}
          。{{t('common.label.serialNumber')}}：
          {{ item.content.toBizNo }}
        </template>

        <template v-else>
          <template v-if="isOpenData && item.executorStaffId">
            <open-data type="userName" :openid="item.executorStaffId"></open-data> 
          </template>
          <template v-else>
            {{ item.executorName }} 
          </template>
          {{$t('part.components.partRecord.text16', {data1: item.action, data2: item.showInOwn == 1?$t('part.components.partRecord.text1'):''})}}

          <template slot="content">
            <p v-if="item.content.updateContent"><biz-comment-html :html="item.content.updateContent"></biz-comment-html></p>
            <base-preview v-if="item.attachments" :files="item.attachments" readonly></base-preview>
          </template>
        </template>

        <template slot="time">{{item.createTime | formatDate}}</template> 
        <i slot="icon" class="el-icon-message"></i>
      </base-timeline-item>
    </base-timeline>
    
    <div class="part-empty-tip" v-else>{{$t('common.base.tip.noData')}}</div>
  </div>
</template>

<script>
import BasePreview from 'packages/BasePreview';
import { isOpenData } from '@src/util/platform';
import { formatDate } from 'pub-bbx-utils';
// import { ConnectorModuleTriggerRecordMixin } from '@src/modules/connector'

export default {
  name: 'part-record',
  inject: ['initData'],
  props: ['items'],
  // mixins: [ConnectorModuleTriggerRecordMixin],
  components: {
    [BasePreview.name]: BasePreview
  },
  data() {
    return {
      isOpenData
    }
  },
  filters: {
    formatDate (val) {
      if (!val) return '';
      return formatDate(val);
    },
  },
}
</script>

<style lang="scss">
.part-record{
  padding: 0 10px;
}
</style>

